package fun.ipconfig.shopping.configure.exception;

import org.springframework.http.HttpStatus;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import fun.ipconfig.shopping.entity.Result;

/**
 * Controller 异常处理
 * @author gtl
 */
@RestControllerAdvice
public class ResultExceptionController {

    @ExceptionHandler({ResultException.class})
    public Result restException(ResultException exception){
        return exception.getResult();
    }

    @ExceptionHandler(AccessDeniedException.class)
    @ResponseStatus(HttpStatus.FORBIDDEN)
    public Result authenticationError(AccessDeniedException exception){
        return new Result().setMsg("无权限操作").setStatus(403);
    }
}
